<?php
/**
 * 巡展同步数据日志
 * @author Administrator
 *
 */
class xDataLogModel extends MY_Model{
    var $typeList = array(1=>'项目预算',2=>'广宣预算',3=>'线下活动预算',4=>'项目结算',5=>'广宣结算',6=>'线下活动结算');
    function xDataLogModel(){
        parent::MY_Model();
        $this->table = 'XDataLog';
    }
    /**
     * 获取类型列表
     * @return multitype:string
     */
    function getTypeList(){
        return $this->typeList;
    }
    /**
     * 包装数据(non-PHPdoc)
     * @see MY_Model::packing()
     */
    function packing($list){
        foreach ($list as $k=>$v){
            $list[$k]['typeName'] = isset($this->typeList[$v['type']]) ? $this->typeList[$v['type']] : '';
            $list[$k]['dataStr'] = $this->dataDecode($v['type'], $v['data']);
        }
        return $list;
    }
    function dataDecode($type, $dataJson) {
        $decodeJson = jsonDecode($dataJson);
        if (in_array($type, array(1,4))){
            $keyNameList = array(
                'dlrNo'=>'专营店编号','activityName'=>'活动主题','activityAddress'=>'活动地址',
                'activityTime'=>'活动时间段','activityType'=>'活动类型','activityCost'=>'<font color="blue">活动额度</font>','budgetApply'=>'<font color="blue">预算总费用</font>',
                'orderStatus'=>'站点状态','siteSpecs'=>'巡展类型标志','settleApply'=>'<font color="blue">结算申请总费用</font>','clearingPath'=>'结算凭证','kpi'=>'KPI系数','settleMoney'=>'结算金额'
            );
            $valueList = array();
            foreach ($decodeJson as $k=>$v){
                if (isset($keyNameList[$k])){
                    $valueList[] = $keyNameList[$k].'："'.$v.'"';
                }
            }
            return implode(',', $valueList);
        }elseif (in_array($type, array(2,5))){
            $keyNameList = array(
                'adType'=>'媒体类型','adName'=>'媒体名称','adSpecification'=>'投放规格','adTime'=>'发布时间段',
                'adCount'=>'发布频次','budgetApply'=>'<font color="blue">预计费用</font>','settleApply'=>'<font color="blue">实际费用</font>'
            );
            $valueList = array();
            foreach ($decodeJson as $k=>$v){
                if (isset($keyNameList[$k])){
                    $valueList[] = $keyNameList[$k].'："'.$v.'"';
                }
            }
            return implode('；', $valueList);
        }elseif (in_array($type, array(3,6))){
            $keyNameList = array(
                'activityAddress'=>'活动地址','activityTime'=>'活动时间段','budgetApply'=>'<font color="blue">预计费用</font>','settleApply'=>'<font color="blue">实际费用</font>'
            );
            $keyNameList2 = array(
                'detailType'=>'费用明细类型','detailName'=>'费用明细名称','detailTime'=>'活动时间段','budgetApply'=>'<font color="blue">预计费用</font>','settleApply'=>'<font color="blue">实际费用</font>'
            );
            $xunDetailType = $this->config->item('xunDetailType');
            $xunDetailName = $this->config->item('xunDetailName');
            $valueList = array();
            foreach ($decodeJson as $k=>$v){
                if (isset($keyNameList[$k])){
                    $valueList[] = $keyNameList[$k].'："'.$v.'"';
                }
            }
            $valueList2 = array();
            if (isset($decodeJson->detailData)){
                foreach ($decodeJson->detailData as $k => $v){
                    $valueList3 = array();
                    foreach ($v as $kk => $vv){
                        if (isset($keyNameList2[$kk])){
                            if ($kk == 'detailType'){
                                $vv = isset($xunDetailType[$vv]) ? $xunDetailType[$vv] : '';
                            }
                            if ($kk == 'detailName'){
                                $vv = isset($xunDetailName[$decodeJson->detailData[0]->detailType][$vv]) ? $xunDetailName[$decodeJson->detailData[0]->detailType][$vv] : '';
                            }
                            $valueList3[] = $keyNameList2[$kk].'："'.$vv.'"';
                        }
                    }
                    $valueList2[] = implode('；', $valueList3);
                }
            }
            $valueList[] = '<br><font color="blue">线下活动明细：</font><br>'.implode('<br>', $valueList2);
            return implode('；', $valueList);
        }
        return '';
    }
}